@extends('admin.layouts.master')

@section('content')

<div class="row aw-form aw-form-explore" id="Data-Form" style="display:none;">
	<div class="col-md-12">
		<section class="panel aw-content">
			<header class="panel-heading">{{$nav_name}}</header>
			<form class="row cmxform form-horizontal tasi-form panel-body aw-canshu" id="Form-Validate">
				<div class="col-lg-12 overflow-hidden">
					<div class="col-lg-3 col-md-2"></div>
					<div class="col-lg-6 col-md-8">
						<div class="form-group">
							<label class="control-label col-lg-12">登录名：</label>
							<div class="col-lg-12">
								<input class="form-control disabled" type="text" placeholder="请输入姓名" id="name" name="name" v-model="data.name" v-bind:value="data.name">
							</div>
						</div>
						<div class="form-group">
	                        <label class="control-label col-lg-12">职位：</label>
	                        <div class="col-lg-12">
	                            <select class="form-control" id="id_join" name="id_join" v-model="data.id_join" v-bind:value="data.id_join">
	                            	<option value="">请选择职位</option>
	                            	<option v-for="(list,key) in join_list" :value="list.id">@{{list.name}}</option>
	                            </select>
	                        </div>
	                    </div>
	                    <div class="form-group">
							<label class="control-label col-lg-12">手机号：</label>
							<div class="col-lg-12">
								<input class="form-control" type="text" placeholder="请输入手机号" id="phone" name="phone" v-model="data.phone" v-bind:value="data.phone">
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-lg-12">密码：</label>
							<div class="col-lg-12">
								<input class="form-control" type="text" placeholder="请输入密码" id="pwd" name="pwd" v-model="data.pwd" v-bind:value="data.pwd">
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-lg-12">再次输入密码：</label>
							<div class="col-lg-12">
								<input class="form-control" type="text" placeholder="请再次输入密码" id="pwd2" name="pwd2" v-model="data.pwd2" v-bind:value="data.pwd2">
							</div>
						</div>
					</div>
				</div>
				<div class="col-md-12 aw-content-btn" :data-status="data.status">
					<button class="btn btn-gules" type="submit">
					@if ($_GET['id']!='add')
						保存
					@elseif ($_GET['id']=='add')
						添加
					@endif	
					</button>
					<a class="btn btn-gray" href="/admin/admin/list?page_id=14">取消</a>
				</div>
			</form>
		</section>
	</div>
</div>

@section('pagejs')
@parent

<!--表单验证-->
<script type="text/javascript" src="/admin/js/jquery.validate.min.js"></script>
<script type="text/javascript">
var Http_id=GetQueryString("id");
var ajax_data={
	api:'/adminapi/admin/admin-info',
	form_data:{id:Http_id},
	tips:false,
}
var VD_data={
	id:'',pwd:'',pwd2:'',id_join:'',
}
var Ajax_Vue_Fun=function(vue_data){
	console.log(vue_data)
	Info_Class_List('join')//获取分类
	vm=new Vue({
		el:'#Data-Form',
		data:{
			data:vue_data,
			join_list:[],
		},
		methods:{
			Save:function(){
				console.log(this.data);
				var ajax_data_edit={
					api:'/adminapi/admin/admin-save',
					form_data:this.data,
					tips:'{{$nav_name}}成功',
					to_url:'/admin/admin/list?page_id=14',
				}
				postData(ajax_data_edit)
			}
		},watch:{
			'data.status':function(val,oldval){
            	//监听变化
            	this.status=1;
            	console.log(vm.status)
        	}
        }
	})
	console.log('vm')
	console.log(vm)
	$('#Data-Form').fadeIn(0)
	$.validator.setDefaults({
        submitHandler: function() {
            vm.Save();
        }
    });
    $().ready(function(){
        $("#Form-Validate").validate({
            rules: {
                name:'required',
                id_join:'required',
                phone:'required',
                pwd:'required',
                pwd2:{
                    required:true,
                    equalTo:'#pwd'
                }
            },
            messages: {
                name:'请输入姓名',
                id_join:'请选择职位',
                phone:'请输入手机号',
                pwd:'请输入密码',
                pwd2:{
                    required:'请再次输入密码',
                    equalTo:'两次密码输入不一致'
                }
            }
        });
    });
}
if(Http_id=='add'){
	console.warn('Vue-function:发布职位事件 id='+Http_id);
	Ajax_Vue_Fun(VD_data)
}else{
	console.warn('Vue-function:编辑职位事件 id='+Http_id);
	Left_Nav_Active('','管理员列表')
	getData(ajax_data,Ajax_Vue_Fun)
	$('#name').attr('disabled','disabled')
}
</script>
@endsection

@endsection

